package com.mxprojects.gui
{
	import com.mxprojects.constructors.CheckboxConstructor;
	import com.mxprojects.constructors.Divider;
	import com.mxprojects.constructors.DrawBorder;
	import com.mxprojects.io.Config;
	import com.mxprojects.io.CustomEvent;
	import com.mxprojects.language.Language;
	import com.mxprojects.language.Word;
	
	import flash.text.TextField;
	
	public class PrivateHeader extends BaseForumElement
	{
		private const DIVIDER_COUNT:int = 3;
		
		public var username:TextField;
		public var subject:TextField;
		public var date:TextField;
		
		public var checkBox:CheckboxConstructor;
		
		public var location:String;
		
		public function PrivateHeader(location:String){
			//set the CSS data up
			username.styleSheet = Styles.css;
			subject.styleSheet = Styles.css;
			date.styleSheet = Styles.css;
			
			//reset everything so that the resize moves stuff
			background.width = 1;
			subject.x = username.x;
			date.x = username.x;
			
			//set the location
			this.location = location;
						
			//the header labels will say different things depending on which section we are in
			//set the defult stuff to inbox
			var userText:String = Language.main(Word.FROM);
			var dateText:String = Language.main(Word.RECEIVED);
			
			switch(location){
				case Word.OUTBOX:
					userText = Language.main(Word.TO);
					dateText = Language.main(Word.SENT);
				break;
				
				case Word.TRASH:
					dateText = Language.main(Word.DATE);
				break;
			}
			
			//populate the labels
			username.htmlText = "<span class=\"privateHeaderUsername\">" + userText + "</span>";
			subject.htmlText = "<span class=\"privateHeaderSubject\">" + Language.main(Word.SUBJECT) + "</span>";
			date.htmlText = "<span class=\"privateHeaderDate\">" + dateText + "</span>";
			
			//place a checkbox to delete the message
			checkBox = new CheckboxConstructor("", "delete");
			checkBox.x = Config.TEXT_PADDING/2;
			checkBox.y = Math.round(background.height/2 - checkBox.height/2);
			checkBox.addEventListener(CheckboxConstructor.TOGGLE, toggleDelete, false, 0, true);
			addChild(checkBox);
			
			//parse the CSS
			super.init(".privateHeaderBackground", DIVIDER_COUNT, false);
			
			//place the stuff where it needs to be
			//placeStuff();
		}
		
		private function toggleDelete(event:CustomEvent):void {
			var isChecked:Boolean = event.customParameter[0];
			
			//grab the items and force the checkboxes
			for(var i:int = 0; i < parent.numChildren; i++){
				if(parent.getChildAt(i) is PrivateItem){
					//set the checkbox if it's a pm item
					var pmItem:PrivateItem = parent.getChildAt(i) as PrivateItem;
					pmItem.setCheckBox(isChecked);
				}
			}
		}
		
		override public function resize():void {
			placeStuff();
			super.resize();
		}
		
		protected function placeStuff():void {			
			//stretch out the BG
			background.width = parent.width;
			
			//place titles in proper spot
			subject.x = username.x + username.width + Config.TEXT_PADDING;
			subject.width = Math.round(background.width - subject.x - date.width - Config.TEXT_PADDING*2);
			date.x = Math.round(subject.x + subject.width + Config.TEXT_PADDING); 
			
			//move the dividers
			getDivider(0).x = Math.round(username.x - (Config.TEXT_PADDING/2));
			getDivider(1).x = Math.round(subject.x - (Config.TEXT_PADDING/2));
			getDivider(2).x = Math.round(date.x - (Config.TEXT_PADDING/2));
		}
		
	}
}